﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace The_LarX
{
    public class Node_Timer : Node_Condition
    {        
        public Node_Timer() { Load(); }

        public Node_Timer(VisualScript Script)
            : base(Script) { Load(); }

        private void Load()
        {
            this.descriptionName = "Timer";
            RepresentationType = typeof(VSRBase);
        }

        public int TimeStep { get; set; }
        public bool Restart { get; set; }

        private int Timer;
        public override void Update()
        {
            if (AllConditionsAllow())
            {
                base.Update();

                if (Timer > TimeStep)
                {
                    this.AllowConditions = true;
                    if (Restart)
                        Timer = 0;
                }
                else
                {
                    Timer += Engine.GameTime.ElapsedGameTime.Milliseconds;
                    this.AllowConditions = false;
                }
            }
        }

        public override void SerializeData(SerializeData Data)
        {
            base.SerializeData(Data);

            Data.AddData(CreatedNumber + "TimeStep", this.TimeStep);
            Data.AddData(CreatedNumber + "Restart", this.Restart);
        }

        public override void DeserializeData(SerializeData Data)
        {
            base.DeserializeData(Data);

            this.TimeStep = Data.GetData<int>(CreatedNumber + "TimeStep");
            this.Restart = Data.GetData<bool>(CreatedNumber + "Restart");
        }
    }
}
